// app.js
App({
  globalData: {
    userInfo: null,
    appAddress: {
      caizhilian: "/mobilemode/mobile/view.html?appid=117&mTokenFrom=anonymous&mToken=6FAED8D63E96254A0258421E6F283785",
      didaima: "https://www.e-cology.com.cn/papi/ebuilder/app/anonymous/auth?pageId=879713330764750853&type=anonymous&tenantKey=t7akvdnf84&ebbusinessid=879713330764750853",
      guanwang: "https://www.weaver.com.cn/",
      jincenda: "/mobilemode/mobile/view.html?appid=114&mTokenFrom=anonymous&mToken=B2DD42FF7BA78B3751BDBA3EB50FBB18",
      jingqiaotong: "/mobilemode/mobile/view.html?appid=51&mTokenFrom=anonymous&mToken=FD8C02D73E5D97FA1774377DA00EEBAA",
      jucailin: "/mobilemode/mobile/view.html?appid=118&mTokenFrom=anonymous&mToken=B3CB5A6E8D343F894D16BD1B72942BC2",
      kefu: "/mobilemode/mobile/view.html?appid=58&mTokenFrom=anonymous&mToken=7CDB993EB6898F8CC77DCAC25642B029",
      kehu: "/mobilemode/mobile/view.html?appid=109&mTokenFrom=anonymous&mToken=4B438460828432DC3B6FC796F002DD9B",
      qianliling: "https://jc.qianliling.com:8443/demo/redirect?app=mobile-workBench",
      qiyecen: "/spa/fna/static4mobile/#/newHomePage",
      qys: "https://app59.qiyuesuo.cn/contract/launch?status=REQUIRED&searchStatus=TOTAL&defaultMonth=0&pocToken=w4lCceAoW7CqORbVgAgPiA==",
      shujujicheng: "/mobilemode/mobile/view.html?appid=116&mTokenFrom=anonymous&mToken=8D31245F4BEC1869E48A73067FF0F97F",
      shuzihua: "/mobilemode/mobile/view.html?appid=102&mTokenFrom=anonymous&mToken=0619165F4A15C47E24F998037A9F87CB",
      wenshuding: "https://wsd.e-cology.com.cn/plugin/load.jsp?u=4",
      xiangmu: "/mobilemode/mobile/view.html?appid=108&mTokenFrom=anonymous&mToken=B4A90AB545DEDD2F0FBEF4E5C2862DE6",
      xinchuang: "/mobilemode/mobile/view.html?appid=106&mTokenFrom=anonymous&mToken=61DA2B3C500C669D2C85B0D6557F507D",
      yinkong: "https://e9-yxbpx.qiyuesuo.cn/mobilemode/mobile/view.html?appid=3&mTokenFrom=anonymous&mToken=C3DB0FAD2FD9D8104049FBC7D2D7A03F",
      zhengwu: "/mobilemode/mobile/view.html?appid=105&mTokenFrom=anonymous&mToken=DD15C10BD4607E0F5C86B27EF5D32C8B",
    },
    appAddressList:[
      {
        type: 'shuzihua',
        name: '数字化运营平台',
        weburl: '/mobilemode/mobile/view.html?appid=102&mTokenFrom=anonymous&mToken=0619165F4A15C47E24F998037A9F87CB'
      },
      {
        type: 'xinchuang',
        name: '信创办公',
        weburl: '/mobilemode/mobile/view.html?appid=106&mTokenFrom=anonymous&mToken=61DA2B3C500C669D2C85B0D6557F507D'
      },
      {
        type: 'zhengwu',
        name: '政务办公',
        weburl: '/mobilemode/mobile/view.html?appid=105&mTokenFrom=anonymous&mToken=DD15C10BD4607E0F5C86B27EF5D32C8B'
      },
      {
        type: 'jincenda',
        name: '合同管理',
        weburl: '/mobilemode/mobile/view.html?appid=114&mTokenFrom=anonymous&mToken=B2DD42FF7BA78B3751BDBA3EB50FBB18'
      },
      {
        type: 'kehu',
        name: '客户管理',
        weburl: '/mobilemode/mobile/view.html?appid=109&mTokenFrom=anonymous&mToken=4B438460828432DC3B6FC796F002DD9B'
      },
      {
        type: 'xiangmu',
        name: '项目管理',
        weburl: '/mobilemode/mobile/view.html?appid=108&mTokenFrom=anonymous&mToken=B4A90AB545DEDD2F0FBEF4E5C2862DE6'
      },
      {
        type: 'jingqiaotong',
        name: '采购管理',
        weburl: '/mobilemode/mobile/view.html?appid=51&mTokenFrom=anonymous&mToken=FD8C02D73E5D97FA1774377DA00EEBAA'
      },
      {
        type: 'qiyecen',
        name: '费用管理',
        weburl: '/spa/fna/static4mobile/#/newHomePage'
      },
      {
        type: 'jucailin',
        name: '人事管理',
        weburl: '/mobilemode/mobile/view.html?appid=118&mTokenFrom=anonymous&mToken=B3CB5A6E8D343F894D16BD1B72942BC2'
      },
      {
        type: 'kefu',
        name: '客服管理',
        weburl: '/mobilemode/mobile/view.html?appid=58&mTokenFrom=anonymous&mToken=7CDB993EB6898F8CC77DCAC25642B029'
      },
      {
        type: 'caizhilian',
        name: '知识管理',
        weburl: '/mobilemode/mobile/view.html?appid=117&mTokenFrom=anonymous&mToken=6FAED8D63E96254A0258421E6F283785'
      },
      {
        type: 'qys',
        name: '电子签章',
        weburl: 'https://app59.qiyuesuo.cn/contract/launch?status=REQUIRED&searchStatus=TOTAL&defaultMonth=0&pocToken=w4lCceAoW7CqORbVgAgPiA=='
      },
      {
        type: 'yinkong',
        name: '印控中心',
        weburl: 'https://e9-yxbpx.qiyuesuo.cn/mobilemode/mobile/view.html?appid=3&mTokenFrom=anonymous&mToken=C3DB0FAD2FD9D8104049FBC7D2D7A03F'
      },
      {
        type: 'qianliling',
        name: '信息采集',
        weburl: 'https://jc.qianliling.com:8443/demo/redirect?app=mobile-workBench',
        registerurl:'wx882147b81e35eb1c'
      },
      {
        type: 'wenshuding',
        name: '电子档案',
        weburl: 'https://wsd.e-cology.com.cn/plugin/load.jsp?u=4'
      },
      {
        type: 'didaima',
        name: '低代码构建平台体验',
        weburl: 'https://www.e-cology.com.cn/papi/ebuilder/app/anonymous/auth?pageId=879713330764750853&type=anonymous&tenantKey=t7akvdnf84&ebbusinessid=879713330764750853'
      },
      {
        type: 'shujujicheng',
        name: '数据集成平台',
        weburl: '/mobilemode/mobile/view.html?appid=116&mTokenFrom=anonymous&mToken=8D31245F4BEC1869E48A73067FF0F97F'
      },
      {
        type: 'home',
        name: 'guanwang',
        weburl: 'https://www.weaver.com.cn/'
      },
      {
        type: 'jiuchuanhui',
        name: '营销管理',
        weburl: '/mobilemode/mobile/view.html?appid=109&mTokenFrom=anonymous&mToken=4B438460828432DC3B6FC796F002DD9B'
      },
      {
        type: 'shijingran',
        name: '项目管理',
        weburl: '/mobilemode/mobile/view.html?appid=108&mTokenFrom=anonymous&mToken=B4A90AB545DEDD2F0FBEF4E5C2862DE6'
      },
      {
        type: 'mukelin',
        name: '客服管理',
        weburl: '/mobilemode/mobile/view.html?appid=58&mTokenFrom=anonymous&mToken=7CDB993EB6898F8CC77DCAC25642B029'
      },
    ]
  },
  onShow(){
    wx.setStorageSync('ts', 0)
    this.autoUpdate() //更新新版本
  },
  autoUpdate() { //更新新版本
  	var self = this
  	// 获取小程序更新机制兼容
  	console.log('canUndate',wx.canIUse('getUpdateManager'))
  	if (wx.canIUse('getUpdateManager')) {
      const updateManager = wx.getUpdateManager()
  		//1. 检查小程序是否有新版本发布
  		updateManager.onCheckForUpdate(function(res) {
  			// 请求完新版本信息的回调
  			console.log('hasUpdate',res.hasUpdate)
  			if (res.hasUpdate) {
          wx.setStorageSync('ts', 1)
          //检测到新版本，需要更新，给出提示
  				wx.showModal({
  					title: '更新提示',
  					content: '检测到新版本，是否下载新版本并重启小程序？',
  					success: function(res) {
  						if (res.confirm) {
  							//2. 用户确定下载更新小程序，小程序下载及更新静默进行
  							self.downLoadAndUpdate(updateManager)
  						} else if (res.cancel) {
  							//用户点击取消按钮的处理，如果需要强制更新，则给出二次弹窗，如果不需要，则这里的代码都可以删掉了
  							wx.showModal({
  								title: '温馨提示~',
  								content: '本次版本更新涉及到新的功能添加，旧版本无法正常访问的哦~',
  								showCancel: false, //隐藏取消按钮
  								confirmText: "确定更新", //只保留确定更新按钮
  								success: function(res) {
  									if (res.confirm) {
  										//下载新版本，并重新应用
  										self.downLoadAndUpdate(updateManager)
  									}
  								}
  							})
  						}
  					}
  				})
  			}
  		})
  	} else {
      // 如果希望用户在最新版本的客户端上体验您的小程序，可以这样子提示
      wx.setStorageSync('ts', 2)
  		wx.showModal({
  			title: '提示',
  			content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
  		})
  	}
  },
  /**
   * 下载小程序新版本并重启应用
   */
  downLoadAndUpdate(updateManager) {
  	var self = this
  	wx.showLoading();
  	//静默下载更新小程序新版本
  	updateManager.onUpdateReady(function() {
      wx.setStorageSync('ts', 3)
  		wx.hideLoading()
  		//新的版本已经下载好，调用 applyUpdate 应用新版本并重启
  		updateManager.applyUpdate()
  	})
  	updateManager.onUpdateFailed(function() {
      // 新的版本下载失败
      wx.setStorageSync('ts', 4)
  		wx.showModal({
  			title: '已经有新版本了哟~',
  			content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~',
  		})
  	})
  }
})
